#include <cstdio>
#include <cstring>

int a[ 1001 ];
bool visit[ 1000001 ];

int main( )
{
    int n, i, j;
    bool flag;
    while ( scanf("%d", &n) && n )
    {
        memset( visit, 0, sizeof( visit ) );
        for ( i = 0; i < n; i++ )
        {
            scanf("%d", &a[ i ]);
            j = a[ i ];
            while ( j != 1 )
            {
                if ( j & 1 ) j = ( 3 * j + 1 ) / 2;
                else j /= 2;
                if ( visit[ j ] ) break;
                visit[ j ] = 1;
            }
        }
        flag = false;
        for ( i = n - 1; i >= 0; i-- )
            if ( !visit[ a[ i ] ] )
            {
                if ( flag ) printf(" ");
                flag = true;
                printf("%d", a[ i ]);
            }
        puts("");
    }
    return 0;
}
